package duck;

/**
 * 绿头鸭子类
 */
public class MallardDuck extends Duck {

    public MallardDuck() {
        super("绿色", 1.2);
    }

    public MallardDuck(double heavy) {
        super("绿色", heavy);
    }

    @Override
    public void fly() {
        System.out.println("绿头鸭在高空快速飞行");
    }

    @Override
    public void quack() {
        System.out.println("绿头鸭发出响亮的'嘎嘎嘎'叫声");
    }

    // 重载setHeavy方法
    public void setHeavy(int heavy) {
        this.heavy = heavy;
        System.out.println("重载方法: 设置绿头鸭体重为整数: " + heavy + "kg");
    }

    public void setHeavy(String weightStr) {
        try {
            this.heavy = Double.parseDouble(weightStr);
            System.out.println("重载方法: 设置绿头鸭体重为字符串: " + weightStr + "kg");
        } catch (NumberFormatException e) {
            System.out.println("体重格式错误");
        }
    }

    @Override
    public void display() {
        System.out.println("=== 绿头鸭信息 ===");
        super.display();
        System.out.println("绿头鸭是常见的野生鸭子");
    }
}